﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MyBlog.WebUI.Models;
using System.Web.Security;
using WebMatrix.WebData;
namespace MyBlog.WebUI.Controllers
{
    public class AdminController : Controller
    {

        MyBlogEntities db = new MyBlogEntities();

        [HttpGet]
        public ViewResult Login()
        {

            return View();
        }

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Login(User aUser)
        {
            if (ModelState.IsValid )
            {
       
                User user = db.Users.Where(
                    m => m.userName == aUser.userName && m.userPassword == aUser.userPassword)
                    .OrderBy(m => m.userId)
                    .FirstOrDefault();
                if (user == null)
                    return View();

                FormsAuthentication.SetAuthCookie(user.userName, false);

                return RedirectToAction("Index", "BackStage");
            }
            return View();
        }



    }
}
